package cn.itsource.shop.cntroller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageBean;
import cn.itsource.org.domain.Department;
import cn.itsource.shop.domain.Shop;
import cn.itsource.shop.query.ShopQuery;
import cn.itsource.shop.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
   private IShopService service;

    @PutMapping
    public AjaxResult saveorupdate(@RequestBody Shop shop) {
        System.out.println("来了");
        try {
            if (shop.getId() == null) {
                service.add(shop);
            } else {
                service.update(shop);
            }
        } catch (Exception e) {
            return new AjaxResult(false, "操作失败");
        }
        return new AjaxResult();
    }

    @PostMapping("/settlement")
    public AjaxResult setoo(@RequestBody Shop shop){
        System.out.println(shop);
        try {
            //调用注入的方法
            service.ruzhu(shop);
            //返回成功的信息
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            //返回失败的信息
            return new AjaxResult(false,"失败");
        }
    }
    @PostMapping
    public PageBean<Shop> fenye(@RequestBody ShopQuery query) {
        return service.queryhigt(query);
    }


//删除
@DeleteMapping("/{id}")
public AjaxResult del(@PathVariable("id") Long id) {
    try {
        service.del(id);
    } catch (Exception e) {
        return new AjaxResult(false, "操作失败");
    }
    return new AjaxResult();
}
}
